package com.ddx.controller.core;

import com.ddx.common.exception.ExceptionUtil;
import com.ddx.common.exception.ResultModel;
import com.ddx.dto.ProvideIdeaDto;
import com.ddx.service.ProvideIdeaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 反馈建议
 * 
 * @author xgc
 * @email 1992lcg@163.com
 * @date 2018-10-29 22:44:50
 */
@Api(value="反馈建议")
@RestController
@RequestMapping("/app/user")
public class ProvideIdeaController {
	@Autowired
	private ProvideIdeaService provideIdeaService;

	
	private static Logger logger = LoggerFactory.getLogger(ProvideIdeaController.class);

	/**
	 * 反馈建议
	 * @param provideIdeaDto
	 * @return
	 */
	@ApiOperation(value = "反馈建议添加", notes = "")
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/uploadFeedback", method = { RequestMethod.POST })
	public ResultModel insert(@RequestBody ProvideIdeaDto provideIdeaDto, HttpServletRequest request) {
		ResultModel resultModel = ResultModel.getSuccessInstance();
		try {
			// 获取userId
			provideIdeaDto.setUserId(Integer.parseInt(request.getHeader("userId")));
			provideIdeaService.insert(provideIdeaDto);
			resultModel.setData(null);
		} catch (Exception e) {
			logger.error("登录异常", e);
			resultModel = ExceptionUtil.getMessageException(e);
		}
		return resultModel;
	}



	/**
	 * 我的反馈建议列表
	 */
	@ApiOperation(value = "我的反馈建议列表", notes = "")
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/feedback", method = { RequestMethod.POST })
	public ResultModel list(@RequestBody ProvideIdeaDto provideIdeaDto,HttpServletRequest request){
		ResultModel resultModel = ResultModel.getSuccessInstance();
		try {
			// 获取userId
			// 获取userId
			provideIdeaDto.setUserId(Integer.parseInt(request.getHeader("userId")));
			resultModel.setData(provideIdeaService.list(provideIdeaDto));
		} catch (Exception e) {
			logger.error("登录异常", e);
			resultModel = ExceptionUtil.getMessageException(e);
		}
		return resultModel;
	}
	
}
